package com.itqf.hsh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itqf.hsh.dto.pro;
import com.itqf.hsh.mapper.ProviderMapper;
import com.itqf.hsh.pojo.Provider;
import com.itqf.hsh.service.ProviderService;
import com.itqf.hsh.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.Console;
import java.util.List;

/**
 * projectName: qk_javaproject
 *
 * @author: 肖成扬
 * time: 2021/9/8 14:52
 * description:
 */
@Service
public class ProviderServiceImpl implements ProviderService {

    @Autowired
    private ProviderMapper providerMapper;
    @Override
    public R providers() {
        QueryWrapper<Provider> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",0);
        List<Provider> users = providerMapper.selectList(queryWrapper);
        return R.OK("查询成功！",users);}

    @Override
    public R list(@RequestBody pro Pro) {
        System.out.println("Pro = " + Pro);
        List<Provider> ps = providerMapper.querycha(Pro);
        return R.OK("查询成功！",ps);
    }

    @Override
    public R save(Provider provider) {
        int rows = 0;
        try {
            rows=  providerMapper.insert(provider);
        }catch (Exception e){}
        if(rows==0){
            return R.FAIL("参数异常！");
        }else { return R.OK("插入成功！");}
    }

    @Override
    public R removeUserById(int pid) {
       Provider pro=new Provider();
        pro.setPid(pid);
        pro.setDeleted(1);
       providerMapper.updateById(pro);
        int rows=providerMapper.updateById(pro);

        if (rows==0) {
            return R.FAIL("用户删除失败");
        }
        return R.OK("用户删除成功");
    }

    @Override
    public R updateUser(Provider provider) {
        return null;
    }
}
